

.LC0:
	.string "%d"

.globl main


main:
	pushq %rbp
	movq %rsp,%rbp
	subq $0x1000,%rsp

	movq $0,-0x1000(%rbp) /* p */
	movq $0,-0xff8(%rbp) /* p1 */
	movl $0,-0xff0(%rbp) /* i */
	movq $0,-0xfe0(%rbp) /* p2 */
	movl $0,-0xfe8(%rbp) /* sum */
	movl $0,-0xfc0(%rbp) /* str */

	leaq -0xfc0(%rbp),%rdi 
	movq %rdi,-0x1000(%rbp) /* p */
	call gets

	movl $100,%edi 
	call malloc 
	movq %rax,-0xff8(%rbp) /* p1 */
	movq %rax,-0xfe0(%rbp) /* p2 */

.Lmain_400:
	movq -0x1000(%rbp),%rdi /* p */
	movb (%rdi),%al
	subb $48,%al 

	movq -0xff8(%rbp),%rdi /* p1 */
	movb %al,(%rdi)

	addq $1,-0x1000(%rbp) /* p */
	movq -0x1000(%rbp),%rdi

	addl $1,-0xff0(%rbp) /* i */
	addq $1,-0xff8(%rbp) /* p1 */  
	cmpb $0,(%rdi)
	jne .Lmain_400

.Lmain_300:
	movl -0xff0(%rbp),%eax /* i */
	subl $1,%eax

	movq -0xfe0(%rbp),%rdi /* p2 */
	movb (%rdi),%cl
	movl %eax,%esi 
	movsbl %cl,%edi 
	call power 

	addl %eax,-0xfe8(%rbp)  /* sum */
	subl $1,-0xff0(%rbp) /* i */
	addq $1,-0xfe0(%rbp) /* p2 */

	cmpl $0,-0xff0(%rbp) /* i */
	jne .Lmain_300

	movl -0xfe8(%rbp),%esi /* sum */
	leaq .LC0(%rip),%rdi 
	movl $0,%eax 
	call printf 

	movl $0,%eax
	leave
	ret 

power:
	pushq %rbp
	movq %rsp,%rbp
	subq $0x1000,%rsp
	movl %edi,-0x1000(%rbp) /* num */
	movl %esi,-0xff8(%rbp)  /* power */
	movl $0,-0xff0(%rbp) /* i */
	movl $1,-0xfe0(%rbp) /* */

	cmpl $0,-0x1000(%rbp)
	je .Lpower_1

	cmpl $0,-0xff8(%rbp)
	jne .Lpower_400

	movl $1,%eax 
	jmp .Lpower_0

.Lpower_400:
	movl -0xfe0(%rbp),%eax
	imull $2,%eax
	movl %eax,-0xfe0(%rbp)

	addl $1,-0xff0(%rbp)
	movl -0xff8(%rbp),%eax
	cmpl -0xff0(%rbp),%eax
	jne .Lpower_400

	movl -0x1000(%rbp),%eax /* num */
	imull -0xfe0(%rbp),%eax 
	jmp .Lpower_0

.Lpower_1:
	movl $0,%eax 
.Lpower_0:
	leave
	ret 
